package com.learn.sixday;

import org.apache.log4j.Logger;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @author ln
 * @Description: ${todo}
 * @date 2020/12/14
 */
public class TestParkUnpark {
    private static final Logger log=Logger.getLogger(TestParkUnpark.class);

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            try {
                log.debug("start...");
                TimeUnit.SECONDS.sleep(1);
                log.debug("park...");
                LockSupport.park();
                log.debug("resume...");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t1");
        t1.start();

        try {
            TimeUnit.SECONDS.sleep(2);
            log.debug("unpark....");
            LockSupport.unpark(t1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
}
